package com.qhong.modules.service.impl;

import com.alibaba.fastjson.JSON;
import com.qhong.modules.entity.User;
import com.qhong.modules.service.UserService;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;

/**
 * Created by qhong on 2018/6/7 17:16
 **/
@Service("userService")
public class UserServiceImpl implements UserService {

//	@Override
//	public User queryByMobile(String mobile) {
//		User userEntity = new User();
//		userEntity.setMobile(mobile);
//		return baseMapper.selectOne(userEntity);
//	}

	@Override
	public User selectById(Long id){
		return getUserList().stream().filter(x->x.getId()==id).collect(Collectors.toList()).get(0);
	}

	@Override
	public Long addUser(User u){
		getUserList().add(u);
		System.out.println(JSON.toJSONString(getUserList()));
		return u.getId();
	}

	@Bean
    public List<User> getUserList(){
		List<User> list=new ArrayList<>();
		User u=new User();
		u.setName("hongda");
		u.setId(3L);
		u.setAge(30);
		list.add(u);

		User u2=new User();
		u2.setName("hongda2");
		u2.setId(2L);
		u2.setAge(31);
		list.add(u2);

		return list;
	}
}
